<template>
    <div class="box">
        <header class="header">
            <van-nav-bar title="确认订单" left-arrow @click-left="$router.go(-1)" />
        </header>
        <main class="content">
            <van-cell title="北京市00001号" is-link label="张三  13000000000" />
            <!-- {{ store.orderList }} -->
            <van-swipe-cell v-for="item in store.orderList" :key="item.id">
                <van-card :num="item.count" :price="item.price" :title="item.title" :thumb="item.image" />
            </van-swipe-cell>

        </main>
    </div>
    <footer class="footer">
        <van-submit-bar :price="store.totalPrice * 100" button-text="在线支付" @submit="onSubmit" />
    </footer>
</template>

<script setup>
import request from '@/utils/request'
import { useCounterStore } from '@/stores/counter'
const store = useCounterStore()
const onSubmit = () => {
    let obj = {
        id: new Date().getTime(), // 使用时间戳做唯一值订单id
        title: 'NO' + new Date().getTime(),
        price: store.totalPrice, // 订单总金额
    }
    // 生成订单，状态是待付款
    store.addmyOrder({
        ...obj, // 订单id  订单标题  订单总金额
        orderList: store.orderList, // 该订单中的商品列表
        status: 1  // 订单状态  1待付款 2待发货
    })
    request.get('/pay', {
        params: obj
    }).then(res => {
        if (res.data.code == 200) {
            window.location.href = res.data.data
        }
    })
}
</script>